package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/9/6 4:42
 */
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //分页查询
    @GetMapping("/baseTrademark/{currentPage}/{pageSize}")
    public Result getBaseTrademarkPage(@PathVariable("currentPage") Long currentPage, @PathVariable("pageSize") Long pageSize) {
        //添加分页参数
        Page<BaseTrademark> page = new Page<>(currentPage, pageSize);
        //解析
        page = baseTrademarkService.page(page);
        return Result.ok(page);
    }
    //添加品牌
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    //baseTrademark/get/14
    //根据id获取品牌信息
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademarkById(@PathVariable("id")Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    //根据id修改
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademarkById(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    //删除品牌
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result DeleteBaseTrademark(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
